/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entidades;

import java.io.Serializable;
import java.util.List;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author lomanda
 */
@Entity
@Table(name = "material")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Material.findAll", query = "SELECT m FROM Material m"),
    @NamedQuery(name = "Material.findByIdMaterial", query = "SELECT m FROM Material m WHERE m.idMaterial = :idMaterial"),
    @NamedQuery(name = "Material.findByDescricaoMaterial", query = "SELECT m FROM Material m WHERE m.descricaoMaterial = :descricaoMaterial"),
    @NamedQuery(name = "Material.findByPeso", query = "SELECT m FROM Material m WHERE m.peso = :peso"),
    @NamedQuery(name = "Material.findByUnidade", query = "SELECT m FROM Material m WHERE m.unidade = :unidade")})
public class Material implements Serializable {
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fkMaterial")
    private List<ItemEncomenda> itemEncomendaList;
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @NotNull
    @Column(name = "idMaterial")
    private Integer idMaterial;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "descricaoMaterial")
    private String descricaoMaterial;
    @Basic(optional = false)
    @NotNull
    @Column(name = "peso")
    private float peso;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 45)
    @Column(name = "unidade")
    private String unidade;
    @JoinTable(name = "materialFornecedor", joinColumns = {
        @JoinColumn(name = "fkmaterial", referencedColumnName = "idMaterial")}, inverseJoinColumns = {
        @JoinColumn(name = "fkfornecedor", referencedColumnName = "idFornecedor")})
    @ManyToMany
    private List<Fornecedor> fornecedorList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "fkMaterial")
    private List<Stock> stockList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "material")
    private List<ItemCompra> itemCompraList;

    public Material() {
    }

    public Material(Integer idMaterial) {
        this.idMaterial = idMaterial;
    }

    public Material(Integer idMaterial, String descricaoMaterial, float peso, String unidade) {
        this.idMaterial = idMaterial;
        this.descricaoMaterial = descricaoMaterial;
        this.peso = peso;
        this.unidade = unidade;
    }

    public Integer getIdMaterial() {
        return idMaterial;
    }

    public void setIdMaterial(Integer idMaterial) {
        this.idMaterial = idMaterial;
    }

    public String getDescricaoMaterial() {
        return descricaoMaterial;
    }

    public void setDescricaoMaterial(String descricaoMaterial) {
        this.descricaoMaterial = descricaoMaterial;
    }

    public float getPeso() {
        return peso;
    }

    public void setPeso(float peso) {
        this.peso = peso;
    }

    public String getUnidade() {
        return unidade;
    }

    public void setUnidade(String unidade) {
        this.unidade = unidade;
    }

    @XmlTransient
    public List<Fornecedor> getFornecedorList() {
        return fornecedorList;
    }

    public void setFornecedorList(List<Fornecedor> fornecedorList) {
        this.fornecedorList = fornecedorList;
    }

    @XmlTransient
    public List<Stock> getStockList() {
        return stockList;
    }

    public void setStockList(List<Stock> stockList) {
        this.stockList = stockList;
    }

    @XmlTransient
    public List<ItemCompra> getItemCompraList() {
        return itemCompraList;
    }

    public void setItemCompraList(List<ItemCompra> itemCompraList) {
        this.itemCompraList = itemCompraList;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idMaterial != null ? idMaterial.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Material)) {
            return false;
        }
        Material other = (Material) object;
        if ((this.idMaterial == null && other.idMaterial != null) || (this.idMaterial != null && !this.idMaterial.equals(other.idMaterial))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "entidades.Material[ idMaterial=" + idMaterial + " ]";
    }

    @XmlTransient
    public List<ItemEncomenda> getItemEncomendaList() {
        return itemEncomendaList;
    }

    public void setItemEncomendaList(List<ItemEncomenda> itemEncomendaList) {
        this.itemEncomendaList = itemEncomendaList;
    }
    
}
